home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / shareware / share_41 / assembler / examples / dec_bin_su < prev    next >
Encoding:
Text File  |  1991-05-15  |  1.4 KB  |  57 lines

  1. ; NAME       dec_bin_su
  2. ; PURPOSE    converts the decimal number1 to a binary bit pattern in text1 suppressing 
  3. ;            leading zeros
  4. ; DESIGN     
  5. ;            load number1
  6. ;            start <- false
  7. ;            for i <- 31 down to 0
  8. ;               asl number1
  9. ;               if carry = 1
  10. ;               then
  11. ;                 character = '1'
  12. ;                 start <- true
  13. ;               else
  14. ;                 character = '0'
  15. ;               endif
  16. ;               if i = 31
  17. ;               then
  18. ;                 start <- true
  19. ;               endif
  20. ;               place character at end of text1
  21. ;               if start 
  22. ;               then
  23. ;                 increment text pointer
  24. ;               endif
  25. ;             end for
  26. ;             place control character at end of text1
  27.  
  28. ; NOTE
  29.  
  30.  
  31. ;            r1 stores the address of number to be converted
  32. ;            r4 stores the address of the converted string
  33.  
  34. ;            r6 is loaded with the number to be converted
  35. ;            r7 is used as a loop counter                        (i)
  36. ;            r8 holds a '1' or '0' depending on the carry flag   (character)
  37. ;            r9 is a flag set to 1 when a non zero bit is met    (start)
  38.  
  39. ldr r6, [r1]
  40. mov r7, #31
  41. mov r9, #0
  42. .loop
  43.    movs r6, r6, lsl #1
  44.    movcc r8, #48
  45.    movcs r8, #49
  46.    movcs r9, #1
  47.    cmp   r7, #0
  48.    moveq r9, #1
  49.    strb  r8, [r4] 
  50.    add r4, r4, r9
  51.    subs r7, r7, #1
  52.    bpl loop
  53. mov r8, #0
  54. strb r8, [r4]
  55.  
  56.  
  57.